Multi-Language Support

To this point our XML documents have been free of any imposed rules.  In other words, we have not assigned in document type definitions (DTD’s) to our documents, stipulating the structure of our documents and the types of data that they contain (which we will discuss later).  We have also discussed attribute markup to the point that you can create your own attributes and assign them values.  You now have enough knowledge to create multi-language documents by defining the content of elements using a reserved attribute: xml:lang.

The xml:lang attribute is reserved to identify the language in which an element was written.  The language and country codes are used to differentiate both the language and the version of the language.  The syntax for using the xml:lang attribute is:

<elem xml:lang=”langcode-countrycode”>

The following statement specifies that the contents of the element <elem> is in English using the version that is common in the United States.

<elem xml:lang=”en-US”>Element Data</elem>

The language codes are based on the ISO 639 standard.  Here are some of the more common codes that you may encounter:

Code	Language
ar	Arabic
ch	Chinese
de	German
en	English
es	Spanish
fr	French
gr	Greek
it	Italian
ja	Japanese
nl	Dutch
ru	Russian

The country codes are based on the ISO 3166 standard.  Some of the more common ones are:

Code	Language
AT	Austria
BE	Belgium
CA	Canada
CN	China
DE	Germany
DK	Denmark
EN	England
ES	Spain
FR	France
GR	Greece
IT	Italy
JA	Japan
RU	Russia
US	United States

Tip:	For further information on ISO standards and what they are, there are a number of sites on the web, including the ISO web site (http://www.iso.ch).